#ifndef SYSTEM_HPP
#define SYSTEM_HPP

/////////////////////////////////////////////////////////////////////////////////////////////////// WINDOW STUFF ////////////////////////////////////////////////////////////////////////////////////////////////////////

/* INCLUDE FILES GO HERE */

// include local files
#include <globalDef.hpp>


// DIRECT3D 11 //
// include directx header file
#include <D3D11.h>
//#include <D3DX11.h>
//#include <d3dx10.h>

// include the Direct3D Library file
#pragma comment (lib, "D3D11.lib")
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "d3dx10.lib")



/* CLASSES GO HERE */

// Window Class
class cSystem
{
	// Contructor and deconstrcutor
public:
	cSystem(void) // constructor
	{
		/* Window Stuff */

		// initialise cApp global(s)
		g_hWnd = NULL;

		// Window diamentions
		WindowX = 192;
		WindowY = 100;
		WindowWidthMin = 0;	// width min
		WindowHeightMin = 0;	// height min
		WindowWidthMax = 1024;	// width max
		WindowHeightMax = 768;	// height max 

		// Multisampling
		sampleCount = 1;	// count
		sampleQuality = 0;	// quality


		// clear out the window class for use
		ZeroMemory(&m_wc, sizeof(WNDCLASSEX));

		// set and adjust the window rect area
		m_wr = { WindowHeightMin, WindowWidthMin, WindowWidthMax, WindowHeightMax };        // initialise the window rect values

		/* window stuff */

		///////////////////////////////////////////// BREAK /////////////////////////////////////////////

		/* direct3d stuff */

		// initialise cApp global(s)
		m_d3dswapchain = NULL;  // the pointer to the swap chain interface
		m_d3ddevice = NULL;     // the pointer to our Direct3D device interface
		m_d3ddevcontext = NULL; // the pointer to our Direct3D device context

		
		m_DepthStencilBuffer = NULL;
		m_DepthStencilView = NULL;

		// clear out the struct for use
		ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));
		ZeroMemory(&D3D_viewport, sizeof(D3D11_VIEWPORT));
		ZeroMemory(&m_dpethStencilDesc, sizeof(D3D11_TEXTURE2D_DESC));

		/* direct3d stuff */
	};
	~cSystem(){};



	/*  MEMBERS */

	// Window Member variables
private:
	// the handle for the window, filled by a function
	WNDCLASSEX m_wc;        // this struct holds information for the window class
	MSG m_msg;      // this struct holds Windows event messages

	RECT m_wr;      // structure to hold out window rect information
	short wd, ht;   // width and height information for window rect
	HWND g_hWnd;    // handle to our window

	// Window coordinates
	__int64 WindowX;	// location of top left on screen, horizontally
	__int64 WindowY;	// location of top left on scrren, vertically
	INT64 WindowWidthMin;	// width min
	INT64 WindowHeightMin;	// height min
	INT64 WindowWidthMax;	// width max
	INT64 WindowHeightMax;	// height max 

	// Direct3d11 Member variables
private:
	// initialisation
	IDXGISwapChain *m_d3dswapchain; // the pointer to the swap chain interface
	ID3D11Device *m_d3ddevice;      // the pointer to our Direct3D device interface
	ID3D11DeviceContext *m_d3ddevcontext;   // the pointer to our Direct3D device context

	// create a struct to hold information about the swap chain and depth stencil information
	DXGI_SWAP_CHAIN_DESC scd;	// swapchain information
	D3D11_TEXTURE2D_DESC m_dpethStencilDesc;	// depth stencil view
	ID3D11Texture2D *m_DepthStencilBuffer;
	ID3D11DepthStencilView *m_DepthStencilView;

	// Multipsampling count and quality
	INT64 sampleCount;	// count
	INT64 sampleQuality;	// quality

	// rendering
	ID3D11RenderTargetView *D3D_backbuffer;    // the pointer to our back buffer
	ID3D11Texture2D *p_D3DBackBuffer;       // the canvas
	D3D11_VIEWPORT D3D_viewport;    // view port structure


	/*  FUNCTIONS */

	// Application functions
	bool f_AppInit(void);
	bool f_CleanUpApp(void);

	// Window Functions
public:
	HWND f_gethWnd(void);   // return the window handle
	static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message,     // window procedure
		WPARAM wParam, LPARAM lParam);

	bool f_InitWindow(HINSTANCE hInstance, HWND hWnd, int showWindow);      // initialise window
	int f_RunEngine(void);  // main engine loop
	static bool f_CleanUpWindow(void);


	// Direct3D11 Functions
public:
	// initialisation
	bool f_D3DInit(HWND hWnd);      // initalise direct3d with the window and get a handle to the gfx card
	bool f_CleanUpD3D(void);        // clean up direct3d and release all memory back to the system

	// rendering
	bool f_RenderFrame(void);
};


/////////////////////////////////////////////////////////////////////////////////////////////////// WINDOW STUFF ////////////////////////////////////////////////////////////////////////////////////////////////////////


#endif // SYSTEM_HPP